package rulebase;

import javax.swing.JPanel;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import java.awt.CardLayout;
import java.awt.event.ActionListener;
import java.awt.event.ItemListener;

import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.JCheckBox;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JRadioButton;
import javax.swing.JTree;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeSelectionModel;

public class BasicRulePanel extends JPanel
{
	private JTree inputTree;
	private JTree outputTree;
	private DefaultTreeModel inputTreeModel;
	private DefaultTreeModel outputTreeModel;
	private JRadioButton rdnInput;
	private JRadioButton rdnOutput;
	
	public BasicRulePanel()
	{
		setLayout(null);
		initGUI();
	}
	
	private void initGUI()
	{
		rdnInput = new JRadioButton("Input");
		rdnInput.setBounds(6, 7, 109, 23);
		add(rdnInput);
		
		rdnOutput = new JRadioButton("Output");
		rdnOutput.setBounds(6, 245, 109, 23);
		add(rdnOutput);
		
		JScrollPane spInput = new JScrollPane();
		spInput.setBounds(6, 37, 448, 182);
		add(spInput);
		
		JScrollPane spOutput = new JScrollPane();
		spOutput.setBounds(6, 275, 448, 182);
		add(spOutput);
		
		DefaultMutableTreeNode rootInput = new DefaultMutableTreeNode("Input");
		inputTree = new JTree(rootInput);
		spInput.setViewportView(inputTree);
		
		inputTree.setEditable(false);
	    inputTree.setRootVisible(false);
	    inputTree.setShowsRootHandles(true);
	    inputTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
		
	    DefaultMutableTreeNode rootOutput = new DefaultMutableTreeNode("Output");
		outputTree = new JTree(rootOutput);
		
		spOutput.setViewportView(outputTree);
	    outputTree.setEditable(false);
	    outputTree.setRootVisible(false);
	    outputTree.setShowsRootHandles(true);
	    outputTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
	    
	    inputTreeModel = new DefaultTreeModel(rootInput);
	    outputTreeModel = new DefaultTreeModel(rootOutput);
	
	}
	
	public JTree getInputTree()
	{
		return inputTree;
	}
	
	public JTree getOutputTree()
	{
		return outputTree;
	}
	
	public DefaultTreeModel getInputTreeModel()
	{
		return inputTreeModel;
	}
	
	public void setInputTreeModel(DefaultTreeModel DFM)
	{
		inputTree.setModel(DFM);
	}
	
	public void setOutputTreeModel(DefaultTreeModel DFM)
	{
		outputTree.setModel(DFM);
	}
	
	public DefaultTreeModel getOutputTreeModel()
	{
		return outputTreeModel;
	}
	
	public void setInputTreeListener(TreeSelectionListener TSL)
	{
		inputTree.addTreeSelectionListener(TSL);
	}
	
	public void setOutputTreeListener(TreeSelectionListener TSL)
	{
		outputTree.addTreeSelectionListener(TSL);
	}
	
	public JRadioButton getRdnInput() 
	{
		return rdnInput;
	}

	public void setRdnInput(JRadioButton rdnInput) 
	{
		this.rdnInput = rdnInput;
	}

	public JRadioButton getRdnOutput() 
	{
		return rdnOutput;
	}

	public void setRdnOutput(JRadioButton rdnOutput) 
	{
		this.rdnOutput = rdnOutput;
	}

	public void setRdnInputListener(ItemListener IL)
	{
		rdnInput.addItemListener(IL);
	}
	
	public void setRdnOutputListener(ItemListener IL)
	{
		rdnOutput.addItemListener(IL);
	}
	
}
